﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Interop;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using WebAnalyser.Api;
using WebAnalyser.Library;

using System.Reflection;

using Microsoft.Samples;

namespace WebAnalyser.UI
{
    /// <summary>
    /// Interaction logic for OptionsWindows.xaml
    /// </summary>
    public partial class OptionsWindow : Window
    {
        private bool _changesPending = false;

        public IntPtr Handle
        {
            get
            {
                var interopHelper = new WindowInteropHelper(this);
                return interopHelper.Handle;
            }
        }

        private void Test(string test)
        {
            /*Plugins plugins2 = new Plugins();
            LoadedClassInfo lci = plugins2.GetClassReference(@".\WebAnalyser.CSS.dll", "OptionsControl");
            grid2.Children.Add((UserControl)lci.ClassObject);*/
        }

        private void ChangesPending()
        {
            if (!_changesPending)
            {
                _changesPending = true;
                applyButton.IsEnabled = true;
            }
        }

        public OptionsWindow()
        {
            InitializeComponent();
            /*plugins = new Plugins();
            ci = plugins.GetClassReference(@".\WebAnalyser.CSS.dll", "Options");
            navigationTreeView.Items.Add(plugins.InvokeMethod(ci, "GetSettingsTreeView", null));*/
            Events.Instance.GridUpdateEvent += new TriggerGridUpdate(Test);
            Events.Instance.ChangesPendingEvent += new TriggerChangesPending(ChangesPending);
        }

        private void cancelButton_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
            Common.MainWindow.Focus();
        }

        private void helpButton_Click(object sender, RoutedEventArgs e)
        {
            grid2.Children.Clear();
        }

        private void okButton_Click(object sender, RoutedEventArgs e)
        {
            Settings.WriteValue("Main", "IsConfigured", "true");
            this.Close();
        }
    }
}